// pages/play/index.js
import { request } from "../../request/index";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    songs: {},
    msuic: "",
    isAudios: true,
    palyAnimation: "",
    num:0,
    setInter:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let { ids } = options;
    // 获取音乐详情
    request({ url: "/song/detail", data: { ids } }).then((result) => {
      let { picUrl } = result.data.songs[0].al;
      let { name } = result.data.songs[0].al;
      this.setData({
        songs: {
          picUrl,
          name,
        },
      });
    });
    // 获取音乐地址
    request({ url: "/song/url", data: { id: ids } }).then((result) => {
      let { url } = result.data.data[0];
      this.setData({
        msuic: url,
      });
    });
  },
  // 音乐播放
  handlePlayMusic() {
    let { isAudios } = this.data;
    if (isAudios) {
      this.audioCtx.play();
      this.setData({
        isAudios: !isAudios,
        palyAnimation: "palyAnimation",
      });
    } else {
      this.audioCtx.pause();
      this.setData({
        isAudios: !isAudios,
        palyAnimation: "stop",
      });
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  // 页面加载完毕获取元素
  onReady: function () {
    this.audioCtx = wx.createAudioContext("audios");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
